*Analysis_Rep.do*

********************************************************************************************************************
********************************************************************************************************************

*This code replicates analyses presented in the paper.*

*Please note that to be compliant with data sharing permissions and to protect participants' anonymity, I only include information required to replicate analyses in the replication file.*

*The code below requires that the following programs are installed: rowranks, splitvallabels, and catplot.

*Set your working directory so that you can input data, and so that tables and figures are output to an appropriate folder*
cd " "

***********************************
************Table 1****************
***********************************

use Dataset_StudyPart.dta, clear

*To see rows 1-3*
*Number who started survey, by country and round*
tab Country rnd
*Number who completed survey, by country and round*
tab Country rnd if Finished==1

*To see row 4*
*Number by round who started survey*
tab rnd 
*Number who completed survey, by round*
tab rnd if Finished==1

***********************************
************Figure 1***************
***********************************

*First, generate left panel, for study participants*

*Limit to baseline survey*
keep if rnd==1

*We only include participants who engaged in the ranking exercise, and who we can identify as being a participant from a specific country*
drop if RankImp_6==. | RankImp_7==. | RankImp_9==. | RankImp_10==.
drop if Country==""

*Create a comparative ranking across the four categories, where low values indicate high priority, to ease comparability with OP dataset and categories*
rowranks RankImp_6-RankImp_10, generate(rank1-rank4) 

*Only retain rankings*
keep rank1 rank2 rank3 rank4

*Create row ID*
gen case=_n

*Reshape to long, with one observation per ranking per issue*
reshape long rank, i(case) j(Issue) string

*Relabel variables*
ren rank Ranking
label define Ranking_l 1 "First" 2 "Second" 3 "Third" 4 "Fourth" 
label values Ranking Ranking_l

destring Issue, replace
label define Issue_l 1 "Social Cohesion" 2 "Gender Inequality" 3 "Violent Extremism" 4 "Gender-Based Violence"
label values Issue Issue_l

*Create figure*
splitvallabels Issue
catplot Ranking Issue, ///
percent(Ranking) ///
var1opts(label(labsize(small))) ///
var2opts(label(labsize(small)) relabel(`r(relabel)')) ///
ytitle("Priority Ranking by Issue (Percent of Respondents)", size(small)) ///
blabel(bar, format(%4.1f) size(vsmall)) yscale(r(0,55)) ///
intensity(25) ///
asyvars ///
bar(1, color(black) fintensity(inten70)) ///
bar(2, color(gs6) fintensity(inten70)) ///
bar(3, color(gs11) fintensity(inten60)) ///
bar(4, color(gs14) fintensity(inten80)) ///
legend(rows(1) stack size(small) ///
order(1 "First" 2 "Second" ///
3 "Third" ///
4 "Fourth") ///
symplacement(center) ///
title(Priority, size(small))) graphregion(fcolor(white) icolor(white) lcolor (white) ilcolor(white) ifcolor(white)) scheme(s1color) ylab(, nogrid) title(Study Participants)
graph save Fig1_Left.gph, replace

*Second, generate right panel, for members of OP*
use Dataset_OP.dta, clear

*Create row ID*
gen case=_n

*Reshape to long

ren RankImp_6 RankImp_1
ren RankImp_7 RankImp_2
ren RankImp_9 RankImp_3
ren RankImp_10 RankImp_4

reshape long RankImp_, i(case) j(Issue) string

*Label variables*
ren RankImp_ Ranking
label define Ranking_l 1 "First" 2 "Second" 3 "Third" 4 "Fourth"
label values Ranking Ranking_l

destring Issue, replace
label define Issue_l 1 "Social Cohesion" 2 "Gender Inequality" 3 "Violent Extremism" 4 "Gender-based Violence"
label values Issue Issue_l

*Create figure*
splitvallabels Issue
catplot Ranking Issue, ///
percent(Ranking) ///
var1opts(label(labsize(small))) ///
var2opts(label(labsize(small)) relabel(`r(relabel)')) ///
ytitle("Priority Ranking by Issue (Percent of Respondents)", size(small)) ///
blabel(bar, format(%4.1f) size(vsmall)) yscale(r(0,55)) ///
intensity(25) ///
asyvars ///
bar(1, color(black) fintensity(inten70)) ///
bar(2, color(gs6) fintensity(inten70)) ///
bar(3, color(gs11) fintensity(inten60)) ///
bar(4, color(gs14) fintensity(inten80)) ///
legend(rows(1) stack size(small) ///
order(1 "First" 2 "Second" ///
3 "Third" ///
4 "Fourth") ///
symplacement(center) ///
title(Priority Ranking, size(small))) graphregion(fcolor(white) icolor(white) lcolor (white) ilcolor(white) ifcolor(white)) scheme(s1color) ylab(, nogrid) title(Organizational Partner)
graph save Fig1_Right.gph, replace

*Combine*
grc1leg Fig1_Left.gph Fig1_Right.gph, scheme(s1color) legendfrom(Fig1_Right.gph) imargin(-3 -3 -4 -4) xcommon
graph export "Figure1_Full.tif", replace

***********************************
************Figure 2***************
***********************************

*Load data*
use Dataset_StudyPart.dta, clear

*Drop if midline survey, or missing country information, or if participant did not engage in ranking exercise*
keep if rnd!=2
drop if RankImp_6==. | RankImp_7==. | RankImp_9==. | RankImp_10==.
drop if Country==""

*Encode country variable*
encode Country, gen(CountryN)

*Create a comparative ranking across the four categories, where high values indicate high priority*
rowranks RankImp_6-RankImp_10, generate(rank1-rank4) field

*Keep needed variables*
keep rank1 rank2 rank3 rank4 rnd CountryN

*Create round indicator*
tab rnd, gen(rnd)

*Run and plot regression*
capture drop temp
est clear
local i=0
foreach x in rank1 rank2 rank3 rank4 ///
	{
	local ++i
	di `i'
	gen t`i' = rnd2
	  *Without country fixed effects
  regress `x' t`i' 
      estimates store est`i'
	  drop t`i' 
	  local ++i
	  di `i'
	  gen t`i' = rnd2
	  *With country fixed effects*
	 regress `x' t`i' i.CountryN
      estimates store est`i'
	  drop t`i' 
  }	
  
capture drop temp
gen temp = " " in 1
replace temp =  "{bf: Social Cohesion}" in 2
replace temp =  " " in 3
replace temp =  "{bf:Gender Inequality}" in 4
replace temp = " " in 5
replace temp = "{bf:Violent Extremism}" in 6
replace temp = " " in 7
replace temp = "{bf:Gender-Based Violence}" in 8

coefplot est1 est2 est3 est4 est5 est6 est7 est8, level(95 90) ///
keep(t1 t2 t3 t4 t5 t6 t7 t8) yline(0, lcolor(gs14) lwidth(thin)) ///
scheme(s1color) aspectratio(1) ylab(-1 "-1" -.5 "-.5"  0 "0" .5 ".5" 1 "1") ///
 legend(off) groups(t1 t2 = " " t3 t4 = " " t5 t6 = " " t7 t8 = " ", labsize(tiny)) ///
 vertical  plotregion(lcolor(white)) xscale(range(-0.01 0.05) lcolor(white))  yscale(lcolor(white)) ///
 coeflabel(t1=" " t2=" " t3=" " t4=" " t5=" " t6=" " t7=" " t8=" ", notick) legend(off)  ///
 p1(mcolor(gray%100) msymbol(T) ciopts(lcolor(gray%100 gray%100))) ///
 p2(mcolor(gray%40) msymbol(T) ciopts(lcolor(gray%40 gray%40))) ///
 p3(mcolor(gray%100) msymbol(T) ciopts(lcolor(gray%100 gray%100))) ///
 p4(mcolor(gray%40) msymbol(T) ciopts(lcolor(gray%40 gray%40))) ///  
 p5(mcolor(gray%100) msymbol(T) ciopts(lcolor(gray%100 gray%100))) ///
 p6(mcolor(gray%40) msymbol(T) ciopts(lcolor(gray%40 gray%40))) ///
 p7(mcolor(gray%100) msymbol(T) ciopts(lcolor(gray%100 gray%100))) ///
 p8(mcolor(gray%40) msymbol(T) ciopts(lcolor(gray%40 gray%40))) ///
 grid() ytitle("Over-Time Effect (Endline versus Baseline)", size(small)) ///
 mlabel(temp) mlabsize(tiny) mlabcolor(gs5) mlabangle(vertical) mlabposition(4)
graph export "Figure2.tif", replace 
drop temp
